package service.creditcard;


public abstract class CreditCardServiceFactory {
	
	// factory types
	public static final String MEMORY_FACTORY = "MEMORY";
	public static final String DB_FACTORY = "DB";
	
	private static final CreditCardServiceFactory MEMORY_FACTORY_INSTANCE = new CreditCardServiceFactoryMemory();
	
	/*private static final StudentServiceFactory DEFAULT_FACTORY_INSTANCE = loadDefaultFactory();
		
	private static StudentServiceFactory loadDefaultFactory() {
		StudentServiceFactory result = null;
		Properties properties = new Properties();
		String factoryName = null;
		try {
			FileOutputStream out = new FileOutputStream("Dom.txt");
			out.write(12);
			out.close();
			
			properties.load(new FileInputStream("WEB-INF/webapp.properties"));
			factoryName = properties.getProperty("defaultFactory");
			result = StudentServiceFactory.getFactory(factoryName);
		}
		catch(IOException e){
			throw new IllegalStateException("Properties file webapp.properties was not found.",e);
		}
		
		return result;
	}

*/
	public static CreditCardServiceFactory getFactory(String name){
		if (name.equals(MEMORY_FACTORY)){
			return MEMORY_FACTORY_INSTANCE;
		}
		else {
			throw new IllegalArgumentException("Unknown factory type: " + name);
		}
	}
	
	/*
	public static StudentServiceFactory getDefaultFactory(){
		return DEFAULT_FACTORY_INSTANCE;
	}
	*/
	public abstract CreditCardService getInstance();
	
}
